/**
 * 企业月度申报组件
 * 
 *     var tool=new YearMonthAuditTool();
		tool.initial({
			el:$("#yearMonthAudit"),
			url:"${ctx}/baseInfo/getCompanyYearState.do",
			companyId:"<%=companyId%>",
			year:"<%=year%>",
			month:"<%=month%>",
			onCheckMonth:loadInfo
		});
 * 
 * **/
YearMonthAuditTool = function () {
	var year, month,state;
	var url,companyId,onCheckMonth;
	//初始化控件
	var initial=function(e){
		var div=e.el;
		url=e.url;
		companyId=e.companyId;
		onCheckMonth=e.onCheckMonth;
		
		//渲染控件
		div.css("width","1100px");
		div.css("height","60px");
		div.css("padding","10px");
		div.css("width","1100px");
		var date=new Date();
		date.setMonth(date.getMonth()-1,1);//默认上个月
		year=date.getFullYear();
		month=date.getMonth()+1;
		var year_s="[{id:\""+year+"\",text:\""+year+"\"},{id:\""+(year-1)+"\",text:\""+(year-1)+"\"},{id:\""+(year-2)+"\",text:\""+(year-2)+"\"},{id:\""+(year-3)+"\",text:\""+(year-3)+"\"},{id:\""+(year-4)+"\",text:\""+(year-4)+"\"}]";
		
		if(e.year!=undefined&&e.year!=null&&e.year!=""&&e.year!="null"){
			year=e.year;
		}else{
			year+="";
		}
		if(e.month!=undefined&&e.month!=null&&e.month!=""&&e.month!="null"){
			month=e.month;
		}else{
			if(month<10){
				month="0"+month;
			}else{
				month=""+month;
			}
		}
		div.append("<div style='float:left;width:200px;height:60px;'><div style='text-align:center;margin-top:20px;'>申报历史：<input class='mini-combobox' style='width:80px;' data='"+year_s+"' onvaluechanged='tool.yearClick' value='"+year+"'></div></div>");
		for(var i=1;i<=12;i++){
			var value="";
			if(i<10){
				value="0"+i;
			}else{
				value=""+i;
			}
			div.append("<div value='"+value+"' check_state='false' audit_state='0' class='css_yma_m' style='cursor:pointer;text-align:center;float:left;width:70px;height:60px;border:1px solid;margin:1px;color: #fff' onclick='tool.monthClick(this)'></div>");
		}
		
		$(".css_yma_m").each(function(){
			if($(this).attr("value")==month){
				$(this).css("color","#1cc45f");
				$(this).attr("check_state","true");
			}
		});
		yearClick({value:year});
	};
	//年份选择事件
	var yearClick=function(e){
		year=e.value;
		$.ajax({
		  	  url : url+"?year="+year+"&companyId="+companyId,
		  	  type : "post",
		      async:false,
		      success: function (text) {
		    		$(".css_yma_m").each(function(){
		    			var month_=parseInt($(this).attr("value"));
		    			var state_=text[month_-1];
		    			if(state_==0){
		    				$(this).html("<div style='padding:3px 8px;background: #9a9a9a'><font size='3' color='white'>"+month_+"月</font></div><font color='black' style='height: calc(100% - 26px);display: block;background: #ececec;'>未填报</font>");
		    			}else if(state_==1){
		    				$(this).html("<div style='padding:3px 8px;background: #71819c'><font size='3' color='white'>"+month_+"月</font></div><font color='black' style='height: calc(100% - 26px);display: block;background: #ececec;'>未提交</font>");
		    			}else if(state_==2){
	 	    				$(this).html("<div style='padding:3px 8px;background: #4a84e4'><font size='3' color='white'>"+month_+"月</font></div><font color='black' style='height: calc(100% - 26px);display: block;background: #ececec;'>已提交</font>");
		    			}else if(state_==3){
		    				$(this).html("<div style='padding:3px 8px;background: #1cc45f'><font size='3' color='white'>"+month_+"月</font></div><font color='black' style='height: calc(100% - 26px);display: block;background: #ececec;'>审核通过</font>");
		    			}else if(state_==4){
		    				$(this).html("<div style='padding:3px 8px;background: #e96a6a'><font size='3' color='white'>"+month_+"月</font></div><font color='black' style='height: calc(100% - 26px);display: block;background: #ececec;'>审核不通过</font>");
		    			}
		    			$(this).attr("audit_state",state_+"");
		    			if($(this).attr("check_state")=="true"){
		    				state=state_;
		    			}
		    		});
		      }
		});
		var e={year:year,month:month,state:state};
		onCheckMonth(e);
	};
	//月份点击事件
	var monthClick=function (el){
		$(".css_yma_m").css("color","#fff");
		$(".css_yma_m").attr("check_state","false");
		$(el).css("color","#1cc45f");
		$(el).attr("check_state","true");
		month=$(el).attr("value");
		state=$(el).attr("audit_state");
		var e={year:year,month:month,state:state};
		onCheckMonth(e);
	};
	//刷新控件
	var reload=function(){
		yearClick({value:year});
	};
	//获取返回值
	var getData=function(){
		return {
			year:year,
			month:month,
			state:state
		}
	}
	return {
		initial:initial,
		getData:getData,
		reload:reload,
		yearClick:yearClick,
		monthClick:monthClick
	}
}
